﻿application.onAppStart=function()
{
	trace("Basic File script is up");
}

application.onConnect=function(instance)
{  
	application.acceptConnection(instance);

	instance.writeBinFile = function(array, fileName)
	{
		var file = new File(fileName);
			file.open("binary", "create");
		
		if (file.isOpen)
		{
			for(var i=0; i<array.length; i++)
			{
				file.writeByte(array[i]);
			}
			
			file.close();
			return 1;
			trace("Have binary write file to:"+fileName);
		}
		return 0;
	}
	
	instance.writeFile = function(message, fileName)
	{
		var file = new File(fileName);
			file.open("text", "create");
		
		if (file.isOpen)
		{
			file.write(message);
			file.close();
			return 1;
			trace("Have write file to:"+fileName);
		}
		return 0;
	}
	
	instance.readFile = function(fileName)
	{
		var file = new File(fileName);
			file.open("text", "read");
		
		if (file.isOpen)
		{
			content = file.readAll();
			file.close();
			trace("Have read file from:"+fileName);
			return content;
		}
	}
	
	instance.deleteFile = function(fileName)
	{
		var file = new File(fileName);
			file.remove();
	}
}

application.onDisconnect=function(instance)
{
	trace("someone has left.");
}


